package fr.pud.client.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Observable;

/**
 * The singleton to deal with the suggestion text field and the suggest address.
 * Apr 9, 2012 - OSE.
 * @author Simon Devineau, Adrien Hierry, Leopold Houdin, Pierre Reliquet
 *         Ecole des Mines de Nantes
 *         SuggestionAddresses.java
 */
public class SuggestionAddresses extends Observable {
    /**
     * The singleton
     */
    private static SuggestionAddresses    singleton     = null;
    /**
     * The collection of stations which could be suggested.
     */
    private static Collection<PUDStation> suggestionPUD = new ArrayList<PUDStation>();

    /**
     * @return the singleton.
     */
    public static SuggestionAddresses getSuggestionAddresses() {
        initialize();
        return singleton;
    }

    /**
     * @return the collection of stations which could be suggested.
     */
    public static Collection<PUDStation> getSuggestionPUD() {
        initialize();
        return suggestionPUD;
    }

    /**
     * The initialization for the singleton.
     */
    private static void initialize() {
        if (singleton == null) {
            singleton = new SuggestionAddresses();
        }
    }

    /**
     * Default private constructor for singleton pattern.
     */
    private SuggestionAddresses() {
    }

    /**
     * @param station
     *            the station to add to the collection.
     */
    public void addSuggestionPUD(PUDStation station) {
        initialize();
        suggestionPUD.add(station);
        this.setChanged();
        this.notifyObservers();
    }

    @SuppressWarnings("static-access")
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof SuggestionAddresses) {
            return ((SuggestionAddresses) obj).getSuggestionPUD().equals(
                    this.getSuggestionPUD());
        }
        else {
            return false;
        }
    }
}
